package com.db.client.demo;

import java.io.IOException;
import java.lang.reflect.GenericArrayType;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.db.client.gui.GuiControler;

public class DemoClient {

	private static int search(String[] args, String arg) {
		int index = 0;
		for (String value : args) {
			if (arg.equals(value))
				return index;
			index++;
		}
		return -1;
	}
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		int port = 40000;
		int index = search(args, "-port");
		
		if (index >= 0 && index < args.length - 1) {
			try {
				port = Integer.valueOf(args[index + 1]);
			} catch (NumberFormatException exception) {
				port = 40000;
			}
		}
		InetAddress address = InetAddress.getLocalHost();

		index = search(args, "-address");
		if (index >= 0 && index < args.length - 1) {
			try {
				address = InetAddress.getByName(args[index + 1]);
			} catch (NumberFormatException exception) {
				address = InetAddress.getLocalHost();
			}
		}
		
		//address = InetAddress.getByName("192.168.1.108");
		//port = 4444;
		GuiControler controler = new GuiControler(address, port);
		controler.runGui();
	}

}
